
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        #div1 div {
            width: 200px;
            height: 200px;
            text-align: center;
            line-height: 200px;
            font-size: 50px;
            border: 1px solid;
            display:none;
        }
        input{
            background: #DDDDDD;
            color: red;
            border: 0;
        }
        .active {
            background: red;
            color: #fffdef;
        }
    </style>
</head>

<body>
<div id="div1">
    <input class="active" type="button" value="点击1">
    <input type="button" value="点击2">
    <input type="button" value="点击3">
    <div style="display:block">11111</div>
    <div>22222</div>
    <div>33333</div>
</div>
<script>
    window.onload = function(){
        var t1 = new Tab("div1");
        t1.init();
    };
    function Tab(id){
        this.oParent = document.getElementById(id);
        this.aInput = this.oParent.getElementsByTagName("input");
        this.aDiv = this.oParent.getElementsByTagName("div");
    }
    Tab.prototype.init = function(){
        var This = this;
        for(var i=0; i<this.aInput.length;i++){
            this.aInput[i].index = i;
            this.aInput[i].onclick=function(){
                This.change(this);
            }
        }
    };
    Tab.prototype.change = function(obj){
        for(var i=0; i<this.aInput.length;i++){
            this.aInput[i].className="";
            this.aDiv[i].style.display="none";
        }
        obj.className="active";
        this.aDiv[obj.index].style.display="block";
    }

</script>
</body>

</html>